
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <utils/qqutils.h>

#include <widgets/qqmessagewidget.h>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
  , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}
MainWindow::~MainWindow()
{
	
}

void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
    messages = QQUtils::parseMessage(arg1);
    ui->statusbar->showMessage(QString("解析成功: 共 %1 条消息").arg(messages.length()));

    ui->listWidget->clear();
    foreach (auto var, messages) {
        QListWidgetItem *item = new QListWidgetItem();
        QQMessageWidget *itemWidget = new QQMessageWidget(var);
        item->setSizeHint(itemWidget->sizeHint());

        ui->listWidget->addItem(item);
        ui->listWidget->setItemWidget(item, itemWidget);
    }
}


void MainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (current) {
        QString value = messages.at(ui->listWidget->currentRow()).content.join("\n");
        ui->statusbar->showMessage(QString("消息长度: %1").arg(value.length()));
    }
}

